package com.alone.mybatisplus.datascope.core.loader;

import com.alone.mybatisplus.datascope.conts.DataScopeModel;
import com.alone.mybatisplus.datascope.core.domain.ModelDataScope;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;

import java.util.List;

/**
 * 根据 {@link DataScopeModel} 路由到对应代理 {@link DataScopeHandler} 处理数据权限条件
 *
 * @author Alone
 */
public class RoutingDataScopeLoader implements DataScopeLoader {

    @Lazy
    @Autowired
    private List<DataScopeHandler> handlers;

    @Override
    public void loadFilterValue(ModelDataScope dataScope) {
        for (DataScopeHandler handler : handlers) {
            if (handler.canHandle(dataScope.getModel())) {
                handler.loadFilterValue(dataScope);
                return;
            }
        }
    }

}
